package cn.rongdao.jrkabao.ui.cashcoupon.uicomponent;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.cashcoupon.SelectCashCouponBean;

/**
 * Created by jack on 2017/8/15
 */

public class SelectCashCouponUIComponent extends RelativeLayout {
    public SelectCashCouponUIComponent(Context context) {
        super(context);
    }

    public SelectCashCouponUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SelectCashCouponUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private CashCouponUIComponent cashCouponUIComponent;
    private TextView tvScene;
    private TextView tvReason;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        cashCouponUIComponent = (CashCouponUIComponent) findViewById(R.id.iscc_ll_cash_coupon);
        tvScene = (TextView) findViewById(R.id.iscc_tv_scene);
        tvReason = (TextView) findViewById(R.id.iscc_tv_reason);
    }

    public void setContent(SelectCashCouponBean.ListBean data) {
        setVisibility(View.VISIBLE);
        cashCouponUIComponent.setContent(data);
        if (data.getIs_valid() == 1) {
            if (!FRString.isEmpty(data.getReason())) {
                String[] strings = data.getReason().split("，");
                if (strings.length > 0) {
                    tvScene.setText(strings[0]);
                }
                if (strings.length > 1) {
                    tvReason.setText(strings[1]);
                }
            }
        } else {
            tvScene.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon_invalid_resaon, 0, 0, 0);
            tvScene.setText("不可用原因");
            tvScene.setTextColor(Color.parseColor("#ff0808"));
            tvReason.setText(FRString.valueOf(data.getReason()));
        }
    }
}
